

var username="";
var isdata=0;
var typedata;
var pagindex=0;
var pagesize=10;
var itemIndex = 0;
var tabLoadEndArray = [false, false, false];
var tabScroolTopArray = [0, 0, 0];
typedata=getUrlParam("typedata");
var  userid=getCookie('userid');
mui('body').on('tap','a',function(){document.location.href=this.href;});
if (typedata==1)
{
    document.title="管理员-体验订单列表";
}
if (typedata==3)
{
    document.title="管理员-签约订单列表";
}
if (typedata==5)
{
    document.title="管理员-代理审核列表";
}
function createFragment(me,itemIndex,username) {
    isdata=itemIndex;
    var  userid=getCookie('userid');
    //statustype状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
    var data;
    data={
        typedata: typedata,
        statustype:itemIndex,
        pageindex:pagindex,
        pagesize:pagesize,
        username:username
    }
    if (itemIndex==3)
    {
        data={
            typedata: typedata,
            statustype:4,
            pageindex:pagindex,
            pagesize:pagesize,
            username:username
        }
    }
    if (itemIndex==4)
    {
        data={
            typedata: typedata,
            statustype:5,
            pageindex:pagindex,
            pagesize:pagesize,
            username:username
        }
    }
    var result = '';

    mui.post('/Order/findadminorde', data, function (info) {
        console.log(info);
        var datas = info.object;

        if(datas.length === 0){
            me.lock();
            me.noData();
            me.resetload();
            return;
        }else {
            for (var i = 0; i < datas.length; i++) {
                cold = datas[i];
                result
                    += ''
                    + '    <hgroup class="khfxRow">'
                    + '      <header>下单时间：'+formattime(cold['createtime'])+'</header>'
                    + '      <div class="mid">'
                    + '        <img class="photo" src="'+cold['userimg']+'" >'
                    + '        <span><label>类型：</label>'+gettypedata(cold['typedata'])+'</span> '
                    + '        <span><label>状态：</label>'+getstatustype(cold['statustype'])+'</span> '
                    + '        <span><label>电话：</label>'+cold["phone"]+'</span> '
                    + '        <span><label>订单号：</label>'+cold['id']+'</span> '
                    + '        <span><label>客户：</label>'+cold['username']+'</span> '
                    + '        <span><label>经纪人：</label>'+cold['upusername']+'</span> '
                    + '      </div>'
                    + '      <footer style="height: 40px;">'+adminbutten(cold['typedata'],cold['id'],cold['statustype'],cold['isassitant'],cold['userid'])+'</footer>'
                    + '    </hgroup>';
            }

            $('.khfxPane').eq(itemIndex).append(result);


            if(datas.length %10!=0){
                me.$domDown.html(me.opts.domDown.domNoData);
            }
            else {
                me.resetload();
                pagindex=pagindex+10;
                me.$domDown.html(me.opts.domDown.domRefresh);
            }
        }

    });

};



function updateOrderisassitant(oredid){
    mui.post('/Order/updateOrderisassitant',
        {
            id:oredid
        },
        function(data){
            console.log(data);
            if (data.code){
                window.location.reload();
                mui.toast('申请协助成功！..');
            }
        },'json'
    );
}

$(function () {
    var itemIndex = 0;
    var tabLoadEndArray = [false, false, false];
    var tabScroolTopArray = [0, 0, 0];
    // dropload
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已无数据</div>'
        },
        loadDownFn: function (me) {
            setTimeout(function () {
                createFragment(me, itemIndex,"");
            }, 500);
        }
    });
    $('#searchForm button').on('click', function () {
        username = document.getElementById('searchInput').value;
        if (username==""||username==undefined||username==null) {
            username="";
        }

        $('.khfxPane hgroup').remove();
        pagindex=0;
        pagesize=10;
        createFragment(dropload,itemIndex,username);

    });

    $('.tabHead span').on('click', function () {

        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        var $this = $(this);
        itemIndex = $this.index();
        $(window).scrollTop(tabScroolTopArray[itemIndex]);

        pagindex=0;
        pagesize=10;

        $('.khfxPane hgroup').remove();
        $(this).addClass('active').siblings('.tabHead span').removeClass('active');
        $('.tabHead .border').css('left', $(this).offset().left + 'px');
        $('.khfxPane').eq(itemIndex).show().siblings('.khfxPane').hide();

        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
        }
        dropload.resetload();
    });
});